package com.ruoyi.web.controller.app;

import com.ruoyi.app.domain.BusRulesRegulations;
import com.ruoyi.app.service.IBusRulesRegulationsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @description: 工作手册、规章制度
 */
@RestController
@RequestMapping("/app/rulesRegulations")
public class BusRulesRegulationsController extends BaseController {

    @Resource
    private IBusRulesRegulationsService busRulesRegulationsService;


    /**
     * 查询业务数据--规章制度列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BusRulesRegulations busRulesRegulations){
        startPage();
        List<BusRulesRegulations> list = busRulesRegulationsService.selectBusRulesRegulationsList(busRulesRegulations);
        return getDataTable(list);
    }


    /**
     * 导出业务数据--规章制度列表
     */
    //@PreAuthorize("@ss.hasPermi('business:regulations:export')")
    @Log(title = "业务数据--规章制度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusRulesRegulations busRulesRegulations)
    {
        List<BusRulesRegulations> list = busRulesRegulationsService.selectBusRulesRegulationsList(busRulesRegulations);
        ExcelUtil<BusRulesRegulations> util = new ExcelUtil<BusRulesRegulations>(BusRulesRegulations.class);
        util.exportExcel(response, list, "业务数据--规章制度数据");
    }

    /**
     * 获取业务数据--规章制度详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:regulations:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(busRulesRegulationsService.selectBusRulesRegulationsByFileId(fileId));
    }

    /**
     * 新增业务数据--规章制度
     */
    //@PreAuthorize("@ss.hasPermi('business:regulations:add')")
    @Log(title = "业务数据--规章制度", businessType = BusinessType.INSERT)
    @PostMapping("/saveBusRulesRegulations")
    public AjaxResult add(@RequestBody BusRulesRegulations busRulesRegulations)
    {
        return toAjax(busRulesRegulationsService.insertBusRulesRegulations(busRulesRegulations));
    }

    /**
     * 修改业务数据--规章制度
     */
    //@PreAuthorize("@ss.hasPermi('business:regulations:edit')")
    @Log(title = "业务数据--规章制度", businessType = BusinessType.UPDATE)
    @PostMapping("updateBusRulesRegulations")
    public AjaxResult edit(@RequestBody BusRulesRegulations busRulesRegulations)
    {
        return toAjax(busRulesRegulationsService.updateBusRulesRegulations(busRulesRegulations));
    }

    /**
     * 删除业务数据--规章制度
     */
    //@PreAuthorize("@ss.hasPermi('business:regulations:remove')")
    @Log(title = "业务数据--规章制度", businessType = BusinessType.DELETE)
    @PostMapping("/deleteById")
    public AjaxResult deleteById( Long fileId)
    {
        return toAjax(busRulesRegulationsService.deleteBusRulesRegulationsByFileId(fileId));
    }



}
